
import java.rmi.RemoteException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;

/**
 *
 * @author olivierm
 */
public class PublisherImpl implements Publisher{
    
    protected Vector listePublishers = new Vector();
    
    public PublisherImpl() throws RemoteException{
        super();
        UnicastRemoteObject.exportObject(this);
    }
    
    public void subscribe(Subscriber obs) throws RemoteException {
        listePublishers.add(obs);
        notifyAllSubscibers();
    }

    public void unsubscribe(Subscriber obs) throws RemoteException {
        listePublishers.remove(obs);
    }

    public int getNbrSubscribes() throws RemoteException {
        return listePublishers.size();
    }

    public void notifyAllSubscibers() throws RemoteException {
        for (int i = 0; i < this.listePublishers.size(); i++){
            Subscriber obs = (Subscriber) this.listePublishers.get(i);
            obs.newValue(this.listePublishers.size());
        }
    }



}
